###########################################
# 创建5个后台执行线程
# 修改线程名、获取线程名
###########################################

import threading
from time import ctime,sleep

#define thread-function first.
def thrfunc_x(arg1, arg2):
	for i in range(500):
	#while True:
		_thr_name = threading.current_thread().getName()
		print "%s running %d times." %(_thr_name, i)
		sleep(1)

#Python thread vector & initialize
threads = [] 
total_thr = 5
for i in range(0, total_thr):
	#@str(integer) -> integer convert to string.
	arg1 = 't' + str(i)
	thrx = threading.Thread(target = thrfunc_x, args = (arg1, i, )) 
	thrx.setName('thr_' + str(i))
	threads.append(thrx)

if __name__ == '__main__':
	for t in threads:
		t.setDaemon(True)
		t.start()
		#print "%s is running." %(t.getName())

	#waitting all threads in 'for-loop' complish.
	t.join()

	print "All over %s" %ctime()